/**
 * MIT License
 * 
 * Copyright (c) 2024 - present @ ebraid
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __EB_FRAMEBUFFER_H__
#define __EB_FRAMEBUFFER_H__


#include <types.h>
#include <config.h>


#ifdef __cplusplus
extern "C" {
#endif


#if CONFIG_FB_COLOR_BIT == 8
typedef struct fb_color {
    uint8_t r: 3;
    uint8_t g: 3;
    uint8_t b: 2;
} fb_color_t;
#elif CONFIG_FB_COLOR_BIT == 16
typedef struct fb_color {
    uint16_t r: 5;
    uint16_t g: 6;
    uint16_t b: 5;
} fb_color_t;
#elif CONFIG_FB_COLOR_BIT == 24
typedef struct fb_color {
    uint32_t r: 8;
    uint32_t g: 8;
    uint32_t b: 8;
} fb_color_t;
#elif CONFIG_FB_COLOR_BIT == 32
typedef struct fb_color {
    uint32_t r: 8;
    uint32_t g: 8;
    uint32_t b: 8;
    uint32_t a: 8;
} fb_color_t;
#else
#error "Unsupported color bit"
#endif


typedef struct framebuffer_info {
    uint16_t    bits_per_pixel;
    uint16_t    xres;
    uint16_t    yres;
    uint16_t    xoffset;
    uint16_t    yoffset;
    uint16_t    vm_xres;
    uint16_t    vm_yres;

} framebuffer_info_t;


typedef struct framebuffer_ops {
    void (*set_pixel)(uint16_t x, uint16_t y, fb_color_t color);
    fb_color_t (*get_pixel)(uint16_t x, uint16_t y);
    void (*fill_rect)(uint16_t x, uint16_t y, uint16_t w, uint16_t h, fb_color_t color);

} framebuffer_ops_t;


typedef struct framebuffer {
    const char *name;
    void     *smem_start;
    size_t   smem_len;
    framebuffer_info_t *info;
    framebuffer_ops_t  *ops;

} framebuffer_t;




#ifdef __cplusplus
}
#endif


#endif // __EB_FRAMEBUFFER_H__